package com.laoniu.service.sys;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laoniu.mapper.SysRoleMenuMapper;
import com.laoniu.entity.SysRoleMenu;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleMenuService extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> {

    @Resource
    private SysRoleMenuMapper roleMenuMapper;

    /**
     * 查询角色菜单列表
     * @param roleId
     * @return
     */
    public List<SysRoleMenu> selectMenuListByRoleId(Long roleId){
        LambdaQueryWrapper<SysRoleMenu> wrapper = Wrappers.lambdaQuery(SysRoleMenu.class);
        wrapper.eq(SysRoleMenu::getRoleId, roleId);
        return roleMenuMapper.selectList(wrapper);
    }

    /**
     * 根据角色id删除菜单
     * @param roleId
     */
    public void deleteByRoleId(Long roleId){
        LambdaQueryWrapper<SysRoleMenu> wrapper = Wrappers.lambdaQuery(SysRoleMenu.class);
        wrapper.eq(SysRoleMenu::getRoleId, roleId);
        roleMenuMapper.delete(wrapper);
    }

}
